package serviceTest;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import service.EquipmentService;
import service.IEquipmentService;
import service.IStaffService;
import common.BasePersistenceTest;
import entity.Company;
import entity.Equipment;
import entity.Staff;

public class StaffServiceTest extends BasePersistenceTest {

	@Autowired
	private IStaffService staffService;
	@Autowired
	private IEquipmentService equipmentService;

	@Test
	public void testGetAllStaffs() {
		Company companyA = new Company("Tencent");

		Staff staffA = new Staff(companyA);
		staffA.setName("xiaowang");

		Staff staffB = new Staff(companyA);
		staffB.setName("xiaoli");

		getPersistenceManager().save(companyA);

		assertEquals(2, staffService.getAllStaffs().size());

	}

	@Test
	public void testGetAllEquipments() {
		Company com = new Company("ser");
		Staff staff = new Staff(com);
		
		Equipment eq1 = new Equipment("eq1", com);
		Equipment eq2 = new Equipment("eq2", com);
		
		equipmentService.login(eq1);
		equipmentService.login(eq2);
		
		getPersistenceManager().save(com);
		getPersistenceManager().save(staff);
		
		assertEquals(0, staffService.getAllEquipments(staff).size());

		equipmentService.borrow(staff, eq1);
		getPersistenceManager().save(staff);

		assertEquals(1, staffService.getAllEquipments(staff).size());
		
		equipmentService.returnEquipment(staff, eq1);
		
		equipmentService.returnEquipment(staff, eq2);
		
		assertEquals(0, staffService.getAllEquipments(staff).size());
		
	}

}
